﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace VPC.EX
{
    public class WriterEX
    {
        public TextWriter tw;

        public WriterEX(string filename)
        {
            tw = new StreamWriter(filename);
        }

        public void export(ContactEX contactObject)
        {   
            tw.WriteLine("BEGIN:VCARD");
            tw.WriteLine("VERSION:4.0");
            tw.WriteLine("N:" + contactObject._given + ";"
                + contactObject._surname + ";"
                + contactObject._prefix + ";"
                + contactObject._suffix + ";");
            tw.WriteLine("FN:" + contactObject._fn);
            tw.WriteLine("ORG:" + contactObject._org);
            tw.WriteLine("TITLE:" + contactObject._title);
            //tw.WriteLine("PHOTO:TYPE=JPEG;ENCODING=BASE64:\n" + EncodeImage(contactObject._photo));
            foreach (Phone ph in contactObject._phoneList)
            {
                    tw.WriteLine("TEL;TYPE=" + ph._phoneType +
                                ",voice;VALUE=tel:" + ph._num);
            }
            foreach (Fax ph in contactObject._faxList)
            {
                tw.WriteLine("TEL;FAX;WORK:" + ph._num);
            }
            foreach (Address ad in contactObject._addrList)
            {
                tw.WriteLine("ADR;TYPE=" + ad._addrType +
                    ";LABEL=" + "\"" + ad._street + "\\n" + ad._city + " " + ad._code + "\\n" + ad._country +
                    ":;;" + ad._street + ";" + ad._city + ";;" + ad._code + ";" + ad._country);
               
            }
            foreach (string str in contactObject._emailList)
            {
                tw.WriteLine("EMAIL:" + str);
            }
            tw.WriteLine("END:VCARD");
            tw.Close();
        }

    }
}
